function Ajax() {
};

Ajax.request = function(url, data, success, opts) {
  var func = function() {
    return $.ajax({
      type : 'POST',
      url : url,
      data : data,
      beforeSend : function() {
        if (!opts || opts.silent != 1) {
          Utils.block_ui(opts);
        }
      },
      success : function(msg) {
        if (!opts || opts.silent != 1) {
          $.unblockUI();
        }
        if (window.__n) {
          window.__n.close();
        }
        if (opts && opts.noobj == 1) {
          success(msg);
        } else {
          obj = Utils.parse(msg);
          if (typeof obj != 'object' && msg != '') {
            window.__n = Utils.message(msg, 'error');
            return;
          }
          success(obj);
        }
      }
    });
  };

  if (opts && opts.confirm == 1) {
    if (!$('#dialog_ajax')[0]) {
      var html = '<div id="dialog_ajax" class="pure-form" style="display: none;" title="' + ((opts && opts.tt) ? opts.tt : 'Confirm') + '">' + 
                   '<div>' + ((opts && opts.txt) ? opts.txt : 'Do you want to continue?')+ '</div>' + 
                 '</div>';
      $('body').append(html);
    }
    $('#dialog_ajax').dialog({
      buttons: {
        'OK': function() {
          $(this).dialog('close');
          return func();
        },
        'Cancel': function() { 
          $(this).dialog('close');
          return null;
        }
      }
    });
  } else {
    return func();
  }
};
